
<?php

include_once dirname(__FILE__).'/class/functions.php';
require_once dirname(__FILE__).'/class/user.class.php';

if(!isset($_GET['actiune'])) $_GET['actiune']='';
$logat = is_logat();
$db = new stdb();
?>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="icon" href="favicon.jpg" type="image/gif" sizes="16x16" /> 
        <link rel="stylesheet" type="text/css" href="./style/style.css" />
        <title>Rezervari Sali</title>
    </head>
<body>
   <? 
        if(what_header()<1)            
         {   
        ?>
        <div id="content">
            <div id="content_inside">
                    <div id="content_inside_sidebar">
                        <ul>
                            <li><a href ="index.php"> Home</a><br />
                            </li><li><a href ="cauta.php"> Cautare</a><br /></li>
                            <li><a href ="rezervare.php"> Rezervari</a><br /></li>                   
                                           
                         </ul>
                                 
                    </div>
            <div id="content_inside_main">
<?


switch($_GET['actiune'])
{
    case '': ?> <form name="logare" action="cont_nou.php?actiune=submit" method=post>
                        <span style="width:120px;display:inline-block;">Utilizator: </span><input type="text" name="user" value=""/> <br/>
                        <span style="width:120px;display:inline-block;"> Parola: </span><input type="password" name="pass" value=""/> <br/>
                        <span style="width:120px;display:inline-block;"> Parola: </span><input type="password" name="pass2" value=""/> <br/>
                        <br/>
                        <span style="width:120px;display:inline-block;">Nume: </span><input type="text" name="nume" value=""/> <br/>
                        <span style="width:120px;display:inline-block;">Prenume: </span><input type="text" name="prenume" value=""/> <br/>
                        <h3> Informatii facultative : </h3>
                        <span style="width:120px;display:inline-block;">Facultatea: </span><input type="text" name="facultatea" value=""/> <br/>
                        <span style="width:120px;display:inline-block;"> An: </span><input type="text" name="an" value=""/> <br/>
                        <span style="width:120px;display:inline-block;">Specialitatea: </span><input type="text" name="specialitatea" value=""/> <br/>
                        <span style="width:120px;display:inline-block;">Numar telefon: </span><input type="text" name="nr_tel" value=""/> <br/>
                        
                        <a href="#" class="grey-button pcb"><span><input type="Submit" value="submit"/></span></a> <br/> <br/> <br/> <br/>
                        </form>
              <?
                   break; 
     case 'submit':
         mysql_safer();
   //      if($_POST['nume']=='' || $_POST['prenume']=='' || $_POST['facultatea']=='' || $_POST['an']=='' || $_POST['specialitatea']=='' || $_POST['nr_tel']=='' || $_POST['user']=='' || $_POST['pass']==''|| $_POST['pass2']=='')
        if($_POST['nume']=='' || $_POST['prenume']=='' || $_POST['user']=='' || $_POST['pass']==''|| $_POST['pass2']=='')
         {
             echo 'Eroare! Completati primele 5 campuri!';
             echo '<form action="cont_nou.php" >
                           <a href="#" class="grey-button pcb"><span><input type="Submit" value="Intoarcere"></input></span></a> <br/> <br/>
                  ';
         }
         else
         {     
             
            if(!empty($_POST['an']) && !empty($_POST['nr_tel'])) 
            $ok = verifica_informatii($_POST['user'],$_POST['pass'],$_POST['an'],$_POST['nr_tel']);
            else 
                $ok = verifica_username($_POST['user'],$_POST['pass']);
            if($ok == 0)
                 die("Informatiile introduse nu sunt valide");
            if(strcmp($_POST['pass'],$_POST['pass2'])!=0)  die("Parolele nu corespund!");
             $parola = md5(md5($_POST['pass']));
           
         
             $user=$_POST['user'];
             
             mysql_query("BEGIN");
             $sql_insert_in_utilizatori = "INSERT INTO `utilizatori` (`ID`,`username`, `parola`,`grup`,`activ`) VALUES ('NULL','".$user."','".$parola."','1','1')";
             $rezultat1= $db->q($sql_insert_in_utilizatori);
             mysql_error();
             $result = $db->q("SELECT ID FROM utilizatori WHERE username='".$user."'");
             if(is_resource($result)){$row=  mysql_fetch_array($result); $uid=$row['ID'];}
             mysql_error();
             
             //if($rezultat1) 
         //        echo $sql_insert_in_utilizatori . "     ID= " .$uid . "   SELECT ID FROM utilizatori WHERE username='".$user."'               ";
             
            
             $sql_insert_in_detalii = "Insert into `detalii_utilizatori` (`ID`, `Nume`, `Prenume`, `Facultate`, `An`, `Specialitatea` ) Values ('".$uid."', '".$_POST['nume']."' , '".$_POST['prenume']."' , '".$_POST['facultatea']."' , '".$_POST['an']."' , '".$_POST['specialitatea']."' )";
             $rezultat2= $db->q($sql_insert_in_detalii);
           //  if($rezultat2)echo $sql_insert_in_detalii . "      ";
             
             $nume=$_POST['nume']." ". $_POST['prenume'];
             $sql_insert_in_carte = "Insert into `carte_telefon` (`user_id`, `nume`, `telefon`) Values ('".$uid."','".$nume."','".$_POST['nr_tel']."')";
             $rezultat3=$db->q($sql_insert_in_carte);
          //   if($rezultat3) echo  $sql_insert_in_carte . "      ";
            
             if( ($rezultat1) && ($rezultat2) && ($rezultat3))
             {
                 mysql_query("COMMIT");
                 echo "User adaugat cu succes";
             }
             else
             {
                 mysql_query ("ROLLBACK");
                 echo "A aparut o eroare: ". mysql_error(). "!";
             }
            
             
        //     echo "<br/>".$uid;
                
             
             
        }
         
}
}
?>
 <? footer(); ?>

 </body>






</html>               
